package com.smart.campus.controller;

import com.smart.campus.dto.SysUser;
import com.smart.campus.pojo.PagedResponse;
import com.smart.campus.pojo.ResponseResult;
import com.smart.campus.service.ShSchoolTeacherServiceFeign;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @BelongsProject: smart-campus
 * @BelongsPackage: com.smart.campus.controller
 * @Author: Y S Z
 * @CreateTime: 2024-09-25  11:00
 * @Description: TODO
 * @Version: 1.0
 */
@Api(tags = "教师管理")
@Slf4j
@RestController
@RequestMapping(value = "shSchoolTeacher")
public class ShSchoolTeacherController {
    @Autowired
    private ShSchoolTeacherServiceFeign shSchoolTeacherFeign;

    @ApiOperation(value = "教师管理列表查询", httpMethod = "POST", notes = "教师管理列表查询")
    @RequestMapping(value = "findShSchoolTeacherList")
    public ResponseResult<List<SysUser>> findShSchoolTeacherList(@RequestBody SysUser sysUser){
        return new ResponseResult<>(200,"教师管理列表查询成功",shSchoolTeacherFeign.findShSchoolTeacherList(sysUser));
    }

    @ApiOperation(value = "教师管理列表分页查询", httpMethod = "POST", notes = "教师管理列表分页查询")
    @RequestMapping(value = "pageSchoolTeacher")
    public ResponseResult<PagedResponse<SysUser>> pageSchoolTeacher(@RequestBody SysUser sysUser, @RequestParam(value = "pageNum")Integer pageNum, @RequestParam(value = "pageSize")Integer pageSize){
        return new ResponseResult<>(200,"教师管理列表分页查询成功",shSchoolTeacherFeign.pageSchoolTeacher(sysUser,pageNum,pageSize));
    }

    @ApiOperation(value = "教师管理新增信息", httpMethod = "POST", notes = "教师管理新增信息")
    @RequestMapping(value = "addSchoolTeacher")
    public ResponseResult addSchoolTeacher(@RequestBody SysUser sysUser){
        try {
            shSchoolTeacherFeign.addSchoolTeacher(sysUser);
            return new ResponseResult<>(200,"新增成功");
        }catch (Exception e) {
            e.printStackTrace();
            return new ResponseResult(444, "新增失败！");
        }
    }

    @ApiOperation(value = "教师管理删除信息", httpMethod = "GET", notes = "教师管理删除信息")
    @RequestMapping(value = "delSchoolTeacher")
    public ResponseResult delSchoolTeacher(@RequestParam(value = "userId")Long userId){
        try {
            shSchoolTeacherFeign.delSchoolTeacher(userId);
            return new ResponseResult<>(200,"删除成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new ResponseResult(444, "新增失败！");
        }
    }

    @ApiOperation(value = "教师管理回显信息", httpMethod = "GET", notes = "教师管理回显信息")
    @RequestMapping(value = "findSchoolTeacherId")
    public ResponseResult<SysUser> findSchoolTeacherId(@RequestParam(value = "userId")Long userId){
        return new ResponseResult<>(200,"回显成功",shSchoolTeacherFeign.findSchoolTeacherId(userId));
    }

    @ApiOperation(value = "教师管理修改信息", httpMethod = "POST", notes = "教师管理修改信息")
    @RequestMapping(value = "updSchoolTeacher")
    public ResponseResult updSchoolTeacher(@RequestBody SysUser sysUser){
        try {
            shSchoolTeacherFeign.updSchoolTeacher(sysUser);
            return new ResponseResult<>(200,"修改成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new ResponseResult<>(444,"修改失败");
        }
    }
}
